package com.xiyou.week05.binarySearch;

/**
 * 154. 寻找旋转排序数组中的最小值 II
 *
 * @ClassName：FindMin
 * @Author：西柚
 * @Date：2022/1/27 11:38 上午
 * @Versiion：1.0
 */
public class FindMin2 {

    public int findMin(int[] nums) {
        int left = 0, right = nums.length - 1;
        while (left < right) {
            int mid = (left + right) / 2;
            if (nums[mid] < nums[right]) {
                right = mid;
            } else if (nums[mid] > nums[right]) {
                left = mid + 1;
            } else {
                right = right - 1;
            }
        }
        return nums[right];
    }

    public static void main(String[] args) {
        int[] nums = new int[]{3, 3, 1, 3};
        FindMin2 findMin = new FindMin2();
        System.out.println(findMin.findMin(nums));
    }

}
